<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
    <!-- table -->
      <FormPanel ref="formPanel" :list="formList1" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <BaseDialog :visible.sync="visibleDrawer" :title="'特殊用户保修期维护新增'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
        <vin @close="closeAdd" @save="saveAdd"></vin>
      </BaseDialog>
      <div style="padding-top: 1rem;"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
        <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { newSave} from '@/api/claim/factory/SpecialUserWarrantyMaintain';
import { partCodeP } from '@/utils/validate';
export default {
  mixins: [dictionary],
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      visibleAdd: false,
      infoId: null,
      saveData: null,
      flterValue: {}, //参数
      res: {}, //返回值
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList1: this.createFormList1(),
    };
  },
  methods: {
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //保存
    chooseOrderNo() {
      this.visibleDrawer = true;
    },
    closeAdd() {
      this.visibleDrawer = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveAdd() {
      this.visibleDrawer = false;
      this.fetchParams = { ...this.fetchParams };
    },
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        this.loading = true;
        let res = await newSave(this.saveData);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({title: '提示信息', message: '保存成功'});
        } else {
          this.loading = false;
          // this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          // this.closeDialog();
        }
      }
    },
    //取消操作
    closeDialog(type) {
      if(type == 'refresh'){
        this.$emit('save');
      } else {
        this.$emit('close', { visibleAdd: false, data: this.selectedRows, type: 'close' });
      }

    },
    add() {},
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '分组代码',
          filterable: true,
          fieldName: 'groupCode',
          placeholder: '请输入分组代码...',
          initialValue: '',
          rules: [{ required: true, validator: partCodeP, trigger: 'blur'},{ required: true, message: '请输入分组代码...', trigger: 'change' },{ min: 1, max: 36, message: '长度在 1 到 36 个字符', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '分组名称',
          filterable: true,
          fieldName: 'groupName',
          placeholder: '请输入分组名称...',
          initialValue: '',
          rules: [{ required: true, message: '请输入分组名称...', trigger: 'change' },{ min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'vpStatus',
          itemList: [{text: '启用', value: 1},{text: '禁用', value: 0}],
          initialValue: 1,
          rules: [{required: true, message: '请选择状态...', trigger: 'change'}]
        }
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
